package com.ymatou.iapi.productlimit.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.ymatou.iapi.productlimit.parameter.OperationProductLimit;
import com.ymatou.iapi.productlimit.parameter.OperationProductLimitBean;
import com.ymatou.iapi.productlimit.parameter.ReturnProductLimit;
import com.ymatou.iapi.productlimit.parameter.ReturnProductLimitBean;
import com.ymatou.iapi.productlimit.service.GetLimitAllowBuyCall;
import com.ymatou.iapi.productlimit.service.ReturnProductLimitCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.ProductLimitCallService;

/**
 * 返还商品限购数量 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ReturnProductLimit {
	private static ReturnProductLimitBean returnproductlimitBean;
	private static ReturnProductLimitCall returnproductlimitCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("返还商品限购数量");
	}

	@Before
	public void caseUp() {
		returnproductlimitBean = new ReturnProductLimitBean();
		returnproductlimitCall = new ReturnProductLimitCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(returnproductlimitCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyData(GetLimitAllowBuyCall getlimitallowbuyCall2, OperationProductLimitBean operationproductlimitBean, ReturnProductLimitBean returnplbean, int truenum) throws InterruptedException {
		Thread.sleep(1000);
		// Thread:main 2017-08-11 14:08:02.093
		// 返回报文{"Code":200,"BCode":0,"Msg":"操作成功","Data":{"Results":[{"ProductId":"2467b5d7-47ea-4e38-af2e-5602073c4d4d","LimitNumber":0,"ActivityLimitNumber":1,"BoughtNumber":0,"ActivityBoughtNumber":1,"ProductInActivityLimitNumber":0,"ProductInActivityBoughtNumber":0}]},"Trace":null}
		Map<String, OperationProductLimit> mop = new HashMap<String, OperationProductLimit>();
		// 用于和查询比较
		for (OperationProductLimit topl : operationproductlimitBean.getOperationProductLimitList()) {
			mop.put(topl.getProductId(), topl);
		}
		JsonArray results = getlimitallowbuyCall2.getJsonObject().getAsJsonObject("Data").getAsJsonArray("Results");
		for (JsonElement jsonElement : results) {
			JsonObject jo = jsonElement.getAsJsonObject();
			OperationProductLimit op = mop.get(jo.get("ProductId").getAsString());
			if (op.getActivityLimit() != null && op.getActivityLimit() > 0) {
				Logger.verifyEquals(op.getActivityLimit(), jo.get("ActivityLimitNumber").getAsInt(), "验证ActivityLimitNumber");
				Logger.verifyEquals(truenum, jo.get("ActivityBoughtNumber").getAsInt(), "验证ActivityBoughtNumber");
			} else if (op.getProductInActivityLimit() != null && op.getProductInActivityLimit() > 0) {
				Logger.verifyEquals(op.getProductInActivityLimit(), jo.get("ProductInActivityLimitNumber").getAsInt(), "验证ProductInActivityLimitNumber");
				Logger.verifyEquals(truenum, jo.get("ProductInActivityBoughtNumber").getAsInt(), "验证ProductInActivityBoughtNumber");
			}
		}

	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnProductLimit_001() {
		Logger.start(true, "返还活动限购数量成功ActivityLimit");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 3, 0, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数2
			int truenum = 2;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ReturnProductLimit_002() {
		Logger.start(true, "返还活动商品限购数量成功ProductInActivityLimit");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数2
			int truenum = 2;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ReturnProductLimit_003() {
		Logger.start(true, "不输入productid,也能成功?");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				// ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数2
			int truenum = 2;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ReturnProductLimit_004() {
		Logger.start(true, "不输入BuyerId,失败");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			// returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
//			Logger.verifyEquals("false", returnproductlimitCall.getString("success"), "验证success");
			Logger.verifyIsContains("买家编号不能小于0", returnproductlimitCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ReturnProductLimit_005() {
		Logger.start(true, "不输入num,不操作");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				// ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数3
			int truenum = 3;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ReturnProductLimit_006() {
		Logger.start(true, "不输入ActivityId,成功");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				// ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数2
			int truenum = 2;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ReturnProductLimit_007() {
		// 这个接口实际是依靠ProductInActivityId来更新数据,ProductInActivityId不输入则更新不成功
		Logger.start(true, "不输入ProductInActivityId,失败");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				// ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数3
			int truenum = 3;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ReturnProductLimit_008() {
		Logger.start(true, "输入num小于0,不操作");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				// ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(-1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数3
			int truenum = 3;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ReturnProductLimit_009() {
		Logger.start(true, "批量返还活动限购数量成功ActivityLimit");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 3, 0, 3, 2);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(1);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数2
			int truenum = 2;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ReturnProductLimit_010() {
		Logger.start(true, "批量返还活动商品限购数量成功ProductInActivityLimit");
		try {
			// 注册用户
						UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
						UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

						JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
						String token = registerResult.get("Token").getAsString();
						Integer userId = urrc.getUserid();

						// 操作,写入限购数据 买3
						OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 0, 3, 3, 2);
						ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
						ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
						// 退1
						returnproductlimitBean.setAppId("AutoTest");
						returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
						List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
						int i=1;
						for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
							ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
							ReturnProductLimit.setActivityId(opl.getActivityId());
							ReturnProductLimit.setProductId(opl.getProductId());
							ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
							ReturnProductLimit.setNumber(i);
//							i++;
							ReturnProductLimits.add(ReturnProductLimit);
						}
						returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
						returnproductlimitCall.setData(returnproductlimitBean);
						returnproductlimitCall.callService();
						Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
						// 剩下购买数2
						int truenum = 3-i;
						verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
								returnproductlimitBean, truenum);


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ReturnProductLimit_011() {
		Logger.start(true, "返回num大于当前购买量,购买量扣减到0");
		try {
			// 注册用户
						UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
						UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

						JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
						String token = registerResult.get("Token").getAsString();
						Integer userId = urrc.getUserid();

						// 操作,写入限购数据 买3
						OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 3, 0, 3, 1);
						ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
						ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
						// 退1
						returnproductlimitBean.setAppId("AutoTest");
						returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
						List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
						for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
							ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
							ReturnProductLimit.setActivityId(opl.getActivityId());
							ReturnProductLimit.setProductId(opl.getProductId());
							ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
							ReturnProductLimit.setNumber(4);
							ReturnProductLimits.add(ReturnProductLimit);
						}
						returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
						returnproductlimitCall.setData(returnproductlimitBean);
						returnproductlimitCall.callService();
						Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
						// 剩下购买数0
						int truenum = 0;
						verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
								returnproductlimitBean, truenum);


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	//需要找到2个可用正常报名的买手 目前创建失败？退货是否有这种场景？
	public void Tc_ReturnProductLimit_012() {
		Logger.start(true, "批量混合返还活动商品限购数量成功ProductInActivityLimit和ActivityLimit");
		try {
			// 注册用户
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();

			// 操作,写入限购数据 买3
			OperationProductLimitBean operationproductlimitBean = ProductLimitCallService.initOperationProductLimitBean(userId, 3, 0, 3, 1);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean));
			
			
			OperationProductLimitBean operationproductlimitBean2 = ProductLimitCallService.initOperationProductLimitBean(userId,0,3, 3, 1,20227567);
			ProductLimitCallService.operationProductLimitCall(operationproductlimitBean2);
			ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean2));
			
			// 退1
			returnproductlimitBean.setAppId("AutoTest");
			returnproductlimitBean.setBuyerId(operationproductlimitBean.getBuyerId());
			List<ReturnProductLimit> ReturnProductLimits = new ArrayList<>();
			for (OperationProductLimit opl : operationproductlimitBean.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(4);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			for (OperationProductLimit opl : operationproductlimitBean2.getOperationProductLimitList()) {
				ReturnProductLimit ReturnProductLimit = new ReturnProductLimit();
				ReturnProductLimit.setActivityId(opl.getActivityId());
				ReturnProductLimit.setProductId(opl.getProductId());
				ReturnProductLimit.setProductInActivityId(opl.getProductInActivityId());
				ReturnProductLimit.setNumber(4);
				ReturnProductLimits.add(ReturnProductLimit);
			}
			returnproductlimitBean.setReturnProductLimitList(ReturnProductLimits);
			returnproductlimitCall.setData(returnproductlimitBean);
			returnproductlimitCall.callService();
			Logger.verifyEquals("200", returnproductlimitCall.getString("Code"), "验证code");
			// 剩下购买数2
			int truenum = 2;
			verifyData(ProductLimitCallService.getLimitAllowBuyCall(ProductLimitCallService.initGetlimitallowbuyBean(operationproductlimitBean)), operationproductlimitBean,
					returnproductlimitBean, truenum);


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
	//未知的异常操作
	public void Tc_ReturnProductLimit_013() {
		Logger.start(true, "批量返还活动限购数量ActivityLimit其中有一个参数异常失败,都不操作");
		try {


		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}